from sqlalchemy.orm import declarative_base
from sqlalchemy.orm import sessionmaker
from sqlalchemy import create_engine, Column, Integer, String,Float,DateTime,ForeignKey,Table,MetaData
from sqlalchemy import text

# 或者使用以下方式连接
engine = create_engine('mysql://yejing:881213@localhost:3306/world')
# 创建基类
Base = declarative_base()

try:
    # 检测连接是否成功
    connect = engine.connect()
    print("连接成功")

    # 执行 SQL 语句
    # result = connect.execute('SELECT * FROM users')
    # connect.execute(text('insert into users(name,age) values("John",40)'))
    result = connect.execute( text('select * from users'))

    # 获取结果集
    for row in result:
        print(row)

except Exception as e:
    print("连接失败：", e)